<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
include_once(APPPATH."libraries/AdminController.php");
class Verifikasi_pagaris extends AdminController {  
	var $bulan = array();
	var $bav_type = "";
	var $bav_title = "";
	function __construct()   
	{
		parent::__construct();    
		$this->_set_action();
		$this->bav_type = 'garis';
		$this->bav_title = 'Garis';
		$this->_set_action(array("detail"),"ITEM");
		$this->_set_title('Transaksi > Verifikasi PA '.$this->bav_title.' PT BAV ');
		$this->DATA->table="tm_bav";
		$this->cat_search = array(
			'all'					=> 'Pilih Kategory',
			'cabang_name'			=> 'Nama Cabang'
		);
		$this->folder_view = "transaksi/";
		$this->_set_cat_search(array("all"	=> $this->cat_search));	
		$this->load->model("mdl_upload_excel_bav","A");
		$this->load->model("mdl_cabang","MC");
		$this->prefix_view = "verifikasi_bav";
		$this->bulan = array(
			"01"	=> "Januari",
			"02"	=> "Februari",
			"03"	=> "Maret",
			"04"	=> "April",
			"05"	=> "Mei",
			"06"	=> "Juni",
			"07"	=> "Juli",
			"08"	=> "Agustus",
			"09"	=> "September",
			"10"	=> "Oktober",
			"11"	=> "November",
			"12"	=> "Desember"
		);
		
		$this->output->enable_profiler(FALSE);
	}

	function index(){
		
		$this->jCfg['isearch']['status'] = "all";
		$this->jCfg['isearch']['per_page'] = '50';
		$this->jCfg['isearch']['start_date'] = date("Y-m-d");
		$this->jCfg['isearch']['end_date'] = date("Y-m-d");
		$this->_releaseSession();
		
		$this->_set_desc_title('Daftar Upload Excel PA '.$this->bav_title.' PT BAV');	
				
		$this->per_page = $this->jCfg['isearch']['per_page'];
		$this->data_table = $this->A->data( array(
				"limit" 	=> $this->per_page, 
				"start_date"=> $this->jCfg['isearch']['start_date'],
				"type"		=> $this->bav_type,
				"end_date"	=> $this->jCfg['isearch']['end_date'],
				"offset" 	=> $this->uri->segment($this->uri_segment)
		) );
		
		$data = $this->_data(array(
				'base_url'		=> $this->own_link.'index'
			)
		);	
					
		$this->_v($this->folder_view.$this->prefix_view,$data);
	}
	
	function verifikasi($id=""){
		if(trim($id) != ""){
			$this->DATA->_update(array(
				'bav_id'		=> dbClean($id)
			),array(
				'bav_approve'	=> 1
			));
			redirect($this->own_link);
		}else{
			redirect($this->own_link);	
		}
		
	}
	
	function search(){
		$this->_set_desc_title('Daftar Upload Excel PA '.$this->bav_title.' PT BAV');	
		$this->load->helper('url');		
		$this->uri_segment = 6;
			
		$column = ''; $keyword = '';				
		if( isset($_POST['column']) && isset($_POST['keyword']) ){
			$column = $_POST['column'];
			$keyword = url_title($_POST['keyword']);
			$this->setiSearch(array(
				"start_date"=> dbClean($_POST['dstart']),
				"end_date"	=> dbClean($_POST['dend']),
				"per_page"	=> dbClean($_POST['per_page'])
			));
		}else{
			$column =  $this->uri->segment(4);
			$keyword =   $this->uri->segment(5);
		}	
				
		$this->per_page = $this->jCfg['isearch']['per_page'];
		$this->data_table = $this->A->data( array(
								"limit" 	=> $this->per_page, 
								"offset" 	=> $this->uri->segment($this->uri_segment),
								"column"	=> $column,
								"type"		=> $this->bav_type,
								"start_date"=> $this->jCfg['isearch']['start_date'],
								"end_date"	=> $this->jCfg['isearch']['end_date'],
								"keyword"	=> (trim($keyword)=="all")?"":$keyword
							) );
		$k=($keyword=="")?"all":$keyword;
		$data = $this->_data(
			array(
				'base_url'		=>$this->own_link.'search/'.$column.'/'.$k
			)
		);	
		
		
		$this->header_page['key']=pTxt(($k=="all")?"":$k);
		$this->header_page['col']=$column;	
		$this->header_page['cat_search'] = array($column	=>	$this->cat_search);	
		$this->_v($this->folder_view.$this->prefix_view,$data);
	}
	
	
	function detail($id=""){
		if(trim($id)=="")
			redirect($this->own_link);	
			
		$this->_set_desc_title('Detail Upload Excel PA '.$this->bav_title.' PT. BAV');

		$m = $this->DATA->data_id(array(
			"bav_id"		=> dbClean($id),
			"bav_status"	=> 1
		));	
		
		if(count($m) > 0){
			$this->DATA->table = "tm_bav_detail";
			$qry = $this->db->query("SELECT * FROM ".$this->DATA->table." WHERE detail_bav = '".$m->bav_id."' 
					ORDER BY detail_order ASC")->result();
			$data['items'] = $qry;
			$data['data'] = $m;
		}else{
			redirect($this->own_link);		
		}
			
		$this->_v($this->folder_view.$this->prefix_view."_detail",$data);
	}
	
}
